package com.cbb.admin.cbb;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.cbb.net.HttpUtils;
import com.cbb.net.MyEmptyViewHelper;
import com.cbb.widget.CustomProgress;

/**
 * Created by jxk on 2018/03/18.
 * Email:676585325@qq.com
 */
public class BaseActivity extends AppCompatActivity {
    public String TAG;
    public Context mContext;
   // public Unbinder unbinder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        TAG = mContext.getClass().getSimpleName();
      //  unbinder = ButterKnife.bind(this);
      /*  //数据采集
        Countly.onCreate(this);
        Countly.sharedInstance().setViewTracking(true);
        Countly.sharedInstance().init(this, "http://123.59.155.7",
                "5f3b7b8ef4b0f6add63e75fcd137c6a9c5235b65", null,
                DeviceId.Type.OPEN_UDID);
        if(!SharedPreUtils.getString(mContext,SharedPre.User.ACCOUNT_UID).equals("")) {
            Countly.sharedInstance().getUserId(SharedPreUtils.getString(mContext,SharedPre.User.ACCOUNT_UID));
        }*/
    }
    @Override
    protected void onResume() {
        super.onResume();
        //   MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //   MobclickAgent.onPause(this);

    }

    @Override
    protected void onStart() {
        super.onStart();
        //   Countly.sharedInstance().onStart(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
     //  unbinder.unbind();
    }

    /**
     * 返回事件
     * @param v
     */
    public void back(View v) {
        onBackPressed();
    }
    /**
     * 移除空白页
     *
     * @param originalView 加载空白页的父View
     * @param emptyView    空白页View
     */
    public void removeEmptyView(View originalView, View emptyView) {
        MyEmptyViewHelper.removeEmptyView(originalView, emptyView);
    }

    /**
     * 设置页面的空白页
     *
     * @param originalView 加载空白页的父View
     * @param emptyView    空白页View
     * @param type         空白页类型
     */
    public View setEmptyView(View originalView, View emptyView, int type) {
        return MyEmptyViewHelper.setEmptyView(originalView, emptyView, type);
    }

    /*public void retry(int tab) {
        if (tab == MyEmptyViewHelper.RETRY_TYPE_GOTO_INDEX) {
            Intent it = new Intent(this, MainActivity.class);
            it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            it.putExtra(MineFragment.EXIT_CURRENT_USER, true);
            startActivity(it);
            onBackPressed();   //结束当activity回到主activity
        }
    }*/

    @Override
    protected void onStop() {
        HttpUtils.cancelAll(mContext, TAG);
      //  Countly.sharedInstance().onStop();
        super.onStop();
    }
    /**
     * 加载进度条
     */
    CustomProgress progressDialog;

    public void showPD() {
        if (null == progressDialog) {
            progressDialog = CustomProgress.show(this, "载入中", true, null);
        }
    }

    public void canclePD() {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }
}
